import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import show from '@dfeidao/atom-web/ui/show';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import format from '@dfeidao/atom-web/dt/format';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import set from '@dfeidao/atom-web/local/set';

export default async function a001(fd: IFeidaoAiBrowserComponent,ss:string) {
	// todo
	set(fd,'ss',ss);
	const res =await nodejs<{d1:{}}>("order-satisfaction/zj-000004/s001",{filter:{work_bill_no:ss}});
	const res2 =await nodejs<{d1:Array<{cust_sat:string}>}>("order-satisfaction/zj-000003/s001","");

	const ret = Array();
	for (let i = 0; i < res2.d1.length; i++) {
		ret[i] = res2.d1[i].cust_sat;
	}
	const q = Array.from(new Set(ret));
	const a = Array();

	for (let i = 0; i < q.length; i++) {
		if(q[i]=="4"){
			a[i]="不满意";
		}else if(q[i]=="1"){
			a[i]="非常满意";
		}else if(q[i]=="2"){
			a[i]="满意";
	
		}else if(q[i]=="3"){
			a[i]="一般";
	
		}else{
			a[i]="请选择";
		}
		const b = Array();
		for (let index = 0; index <q.length; index++) {
			b[index] = {s:q[index],a:a[index]};
		}		

	if(res.d1[0].source_type=="1"){
		res.d1[0].source_type="总服务台";
	}else if(res.d1[0].source_type=="2"){
		res.d1[0].source_type="服务台";

	}else if(res.d1[0].source_type=="3"){
		res.d1[0].source_type="客户报障";

	}else{
		res.d1[0].source_type="内部报障";
	}
	
	if(res.d1[0].work_order_status=="1"){
		res.d1[0].work_order_status="结单";
	}else if(res.d1[0].work_order_status=="2"){
		res.d1[0].work_order_status="完成";

	}else if(res.d1[0].work_order_status=="3"){
		res.d1[0].work_order_status="挂起";

	}else if(res.d1[0].work_order_status=="4"){
		res.d1[0].work_order_status="未派单";
	}else{
		res.d1[0].work_order_status="进行中";
	}
	
	res.d1[0].create_time= format(res.d1[0].create_time, 2);
	res.d1[0].finish_time= format(res.d1[0].finish_time, 2);
	res.d1[0].start_time= format(res.d1[0].start_time, 2);
	
//数据渲染Start
const render_data = Object.assign({},{tol:res.d1},{d1:b});
render(fd,render_data,p001,'p001','inner');
	const see = fd.data.node.querySelector<HTMLDivElement>("[data-id='saw']");
	set_node_cls(see,'display-n',false);
	show(fd.data.node);
	fire('zj-000001','a002');
	fire('zj-000002','a004');
}
}
